package com.throttle.raildroid;
import java.util.EventListener;

import javax.swing.event.EventListenerList;

public class RailEventHandler{
	protected EventListenerList listenerList = new javax.swing.event.EventListenerList();
	
	public void addRailEventListener(RailEventListenerInf listener) {
        listenerList.add(RailEventListenerInf.class, listener);
    }
	
	public void removeRailEventListener(RailEventListenerInf listener) {
        listenerList.remove(RailEventListenerInf.class, listener);
    }
	
	void fireMyEvent(RailEvent evt) {
        Object[] listeners = listenerList.getListenerList();
        // Each listener occupies two elements - the first is the listener class
        // and the second is the listener instance
        for (int i=0; i<listeners.length; i+=2) {
            if (listeners[i]==RailEventListenerInf.class) {
                ((RailEventListenerInf)listeners[i+1]).RailEventOccurred(evt);
            }
        }
    }
}
